package cn.jc.myfile.common.completable;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AutoFillUtil {

    /**
     * 填充map
     */
    private final Map<String, Filler> fillerMap;

    /**
     * 自动填充方法
     *
     * @param t   实体类
     * @param <T> 实体类
     */
    public <T extends AutoFill> void fill(T t) {
        fillerMap.values().forEach(filler -> {
            if (filler.support(t.getClass())) {
                filler.fill(t);
            }
        });
    }
}
